package com.feng.oauth2jwt.myauthen;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.feng.oauth2jwt.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
import org.springframework.stereotype.Component;

/**
 * @author feng
 * @description TODO
 * @date 2019/1/17 15:06
 */
@Component
public class MyJwtTokenStore extends JwtTokenStore {


    private JwtAccessTokenConverter jwtTokenEnhancer;
    /**
     * Create a JwtTokenStore with this token enhancer (should be shared with the DefaultTokenServices if used).
     *
     * @param jwtTokenEnhancer
     */
    public MyJwtTokenStore(JwtAccessTokenConverter jwtTokenEnhancer) {
        super(jwtTokenEnhancer);
        this.jwtTokenEnhancer = jwtTokenEnhancer;
    }

    @Override
    public OAuth2AccessToken getAccessToken(OAuth2Authentication authentication) {
//        System.out.println(JSON.toJSONString(authentication)+"**********************************");
//        JSONObject json = new JSONObject();
//        json.put("hehe", "https://my.oschina.net/yifanxiang");
//        json.put("aaa","aaaaa" );
//        json.put("bbb","aaaaa" );
//        String token = JwtUtils.encode(json);
        System.out.println(JSON.toJSONString(authentication));
//        return this.jwtTokenEnhancer.enhance(null, authentication);
        return super.getAccessToken(authentication);

    }
}
